package com.example.android_29;

import android.content.Intent;
import android.net.Uri;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;

public class SecondActivity extends AppCompatActivity {

    private static final String TAG = "SecondActivity";
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.layout_second);
        Log.d(TAG, "onCreate: ");

        final Intent intent = getIntent();

        Button
                button0 = (Button) findViewById(R.id.button_1),
                button1 = (Button) findViewById(R.id.button_3),
                button2 = (Button) findViewById(R.id.button_4),
                button3 = (Button) findViewById(R.id.button_5),
                button4 = (Button) findViewById(R.id.button_6);
        EditText
                input0 = (EditText) findViewById(R.id.input);


        button0.setOnClickListener(
                new View.OnClickListener(){
                    @Override
                    public void onClick(View v) {
                        Toast.makeText(SecondActivity.this, "firs:"+intent.getStringExtra("extra_data"), Toast.LENGTH_SHORT).show();
                    }
                }
                //v->{finish();}
        );
        button1.setOnClickListener(
                new View.OnClickListener(){
                    @Override
                    public void onClick(View v) {
                        Intent intent = new Intent();
                        intent.putExtra("data_return","data from the front");
                        setResult(RESULT_OK,intent);
                        finish();
                    }
                }
                //v->{finish();}
        );
        button2.setOnClickListener(
                new View.OnClickListener(){
                    @Override
                    public void onClick(View v) {
                        Intent intent = new Intent(Intent.ACTION_VIEW);
                        intent.setData(Uri.parse("https://a.maorx.cn/"));
                        startActivity(intent);
                    }
                }
        );
        button3.setOnClickListener(
                new View.OnClickListener(){
                    @Override
                    public void onClick(View v) {
                        Intent intent = new Intent(Intent.ACTION_DIAL);
                        intent.setData(Uri.parse("tel:10086"));
                        startActivity(intent);
                    }
                }
        );
        button4.setOnClickListener(
                new View.OnClickListener(){
                    @Override
                    public void onClick(View v) {
                        //显示跳转
                        Intent intent = new Intent(SecondActivity.this,FirstActivity.class);
                        startActivity(intent);
                    }
                }
        );

    }

    @Override
    public void onBackPressed() {
        Toast.makeText(this, "pressed back", Toast.LENGTH_SHORT).show();
        Log.d(TAG, "onBackPressed: ");
    }

    @Override
    protected void onStart() {
        super.onStart();
        Log.d(TAG, "onStart: ");
        Log.e(TAG, "onStart: "+this.toString());
    }

    @Override
    protected void onResume() {
        super.onResume();
        Log.d(TAG, "onResume: ");
    }

    @Override
    protected void onPause() {
        super.onPause();
        Log.d(TAG, "onPause: ");
    }

    @Override
    protected void onStop() {
        super.onStop();
        Log.d(TAG, "onStop: ");
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        Log.d(TAG, "onDestroy: ");
    }

    @Override
    protected void onRestart() {
        super.onRestart();
        Log.d(TAG, "onRestart: ");
    }
}
